package org.liyufeng.project.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.liyufeng.project.model.PayrollPersonal;
import org.liyufeng.project.dao.PayrollPersonalDao;
import org.liyufeng.project.util.MySQLUtil;

public class PayrollPersonalDaoImpl implements PayrollPersonalDao{
	private static Logger log = LoggerFactory.getLogger(PayrollPersonalDaoImpl.class);
	
	public ArrayList<PayrollPersonal> getAll(String name){
		ArrayList<PayrollPersonal> list = new ArrayList<PayrollPersonal>();
		String sql = "select * from t_payrollPersonal where name=? order by id desc limit 0,10";
		MySQLUtil mysqlUtil = new MySQLUtil();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			conn = mysqlUtil.getConn();
			ps = conn.prepareStatement(sql);
			ps.setString(1,name);
			rs = ps.executeQuery();			
			while (rs.next()) {
				PayrollPersonal payrollPersonal = new PayrollPersonal();
				payrollPersonal.setDate(rs.getString("date"));
				payrollPersonal.setNumCase(rs.getString("numCase"));
				payrollPersonal.setPayroll(rs.getString("payroll"));				
				list.add(payrollPersonal);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			// 释放资源
			mysqlUtil.releaseResources(conn, ps, rs);
		}
		return list;
	}
	
	public PayrollPersonal getInfoByDate(String name,String date){
		PayrollPersonal payrollpersonal = new PayrollPersonal();
		
		return payrollpersonal;
	}
}
